import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 30318
 * Date: 2023-05-15
 * Time: 18:50
 */
public class Test {
    public static void func4(int[] tmp1) {
        tmp1 = new int[10];
    }

    public static void func5(int[] tmp2) {
        tmp2[0] = 99;
    }

    public static void main(String[] args) {
        int[] array1 = {1, 2, 3, 4, 5};
        func1(array1);

        int[] array2 = {11, 22, 33, 44, 55};
        func2(array2);
    }

    public static void swap(int[] array){
        int tmp = array[0];
        array[0] = array[1];
        array[1] = tmp;
    }

    public static void main12(String[] args) {
        int[] tmp = {1, 2};
        System.out.println("交换前："+tmp[0]+" "+tmp[1]);
        swap(tmp);
        System.out.println("交换后："+tmp[0]+" "+tmp[1]);
    }

    public static int[] func3(){
        int[] tmp = {1, 2, 3, 4, 5, 6, 7};
        return tmp;
    }

    public static void main11(String[] args) {
        int[] ret = func3();
        System.out.println(Arrays.toString(ret));//[1, 2, 3, 4, 5, 6, 7]
    }

    public static void func1(int[] array){
        array = new int[10];//修改了形参自己的指向
    }

    public static void func2(int[] array){
        array[0] = 99;//修改指向对象里面的值
    }

    public static void main10(String[] args) {
        int[] array = {1, 2, 3, 4};
        func1(array);//[1, 2, 3, 4]
        func2(array);//[99, 2, 3, 4]
        System.out.println(Arrays.toString(array));
    }

    public static void main9(String[] args) {
        int[] array = null;//空引用 代表这个引用不指向任何对象
        System.out.println(array);
    }

    public static void main8(String[] args) {
        int[] array = {1, 2, 3, 4};
        int[] array2 = {4, 5, 6, 7, 8};
        array = array2;

        System.out.println(Arrays.toString(array));
        System.out.println(Arrays.toString(array2));
    }

    public static void main7(String[] args) {
        int[] array = {1, 2, 3, 4};
        System.out.println(Arrays.toString(array));//1234

        int[] array2 = array;
        array2[1] = 99;
        System.out.println(Arrays.toString(array));
        System.out.println(Arrays.toString(array2));
        //array2这个引用指向了array这个引用所引用的对象
    }

    public static void main6(String[] args) {
        int a = 10;
        int b = 20;
        int[] array = {1, 2, 3, 4};
        System.out.println(array);
    }

    public static void main5(String[] args) {
        int[] array1 = {1, 2, 3, 4};
        int[] array2 = new int[]{1, 2, 3, 4};
        int[] array3 = new int[10];
    }

    public static void main4(String[] args) {
        int[] array = new int[100];
        for(int i = 0; i < array.length; i++){
            array[i] = i+1;
        }
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }

    public static void main3(String[] args) {
        //1.
        int[] array1 = {1, 2, 3};
        for (int i = 0; i < array1.length; i++) {
            System.out.print(array1[i]+" ");
        }
        System.out.println();

        //2.
        //数组当中数据的类型定义的变量 : 数组名  for each 增强for循环
        for (int x : array1) {
            System.out.print(x+" ");
        }
        System.out.println();

        //3.
        //把数组转变为字符串 然后返回
        String ret = Arrays.toString(array1);
        System.out.println(ret);

        /*System.out.println(array1[1]);

        array1[1] = 99;

        System.out.println(array1[1]);*/
    }

    public static void main2(String[] args) {
        //没有本质区别 只是写法不同
        int[] array1 = {1, 2, 3};//直接赋值 - 静态初始化
        //             new type[] {dates};
        int[] array2 = new int[]{1, 2, 3, 4};//动态初始化

        int[] array3 = new int[10];//只是分配了内存 但是没有进行赋值 只有默认值0

        System.out.println("====");//做断点处理来判断array3里面的初始化默认值

        int[] array4;
        array4 = new int[]{10, 20, 30};

        boolean[] flag = new boolean[10];//默认值为false
        char[] chars = new char[10];

        System.out.println("====");
    }

    public static void main1(String[] args) {
        /*int a1 = 1;
        int a2 = 3;
        int a3 = 3;*/
        //通过数组来组织这些数据
        int [] array = {1, 2, 3};
        float[] array2 = {1.0f, 2.5f};
        int ret = array[1];
        System.out.println(ret);

        int len = array.length;//数组名.长度
        System.out.println(len);
    }
}
